package com.ly.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.base.ResponseData;
import com.ly.dto.CarInfoDto;
import com.ly.entity.Car;
import com.ly.param.CarAuditParam;
import com.ly.param.CarParam;
import com.ly.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;


@Api(tags = "车辆信息发布管理")
@RestController
@RequestMapping("/car")
public class CarController {

    @Autowired
    private CarService carService;


    @ApiOperation(value="新增发布车辆信息")
    @PostMapping
    public ResponseData addCarInfo(@RequestBody Car car, Principal principal) {
        return carService.addCarInfo(car,principal);
    }


    @ApiOperation(value="修改发布车辆信息")
    @PutMapping
    public ResponseData updateCarInfo(@RequestBody Car car, Principal principal) {

        return carService.updateCarInfo(car,principal);

    }


    @ApiOperation(value="审核发布的车辆信息")
    @PostMapping("/audit")
    public ResponseData auditCarInfo(@RequestBody CarAuditParam carAuditParam, Principal principal) {
        return carService.auditCarInfo(carAuditParam,principal);
    }


    @ApiOperation(value="管理员分页查询发布的车辆信息")
    @GetMapping("/adminPage")
    public ResponseData pageCarInfoList(CarParam carParam) {

        return ResponseData.success("查询成功！",carService.pageCarInfoList(carParam));
    }

    @ApiOperation(value="普通用户分页查询发布的车辆信息")
    @GetMapping("/ordinaryPage")
    public ResponseData pageCarInfo(CarParam carParam) {

        return ResponseData.success("查询成功！",carService.pageCarInfo(carParam));
    }


    @ApiOperation(value="会员分页查询自己发布的车辆信息")
    @GetMapping("/vipPage")
    public ResponseData vipPageCarInfoList(CarParam carParam, Principal principal) {

        return ResponseData.success("查询成功！",carService.vipPageCarInfoList(carParam,principal));
    }


    @ApiOperation(value="删除发布的车辆信息")
    @DeleteMapping("/{id}")
    public ResponseData deleteCarInfo(@PathVariable String id) {
        return carService.deleteCarInfo(id);

    }


    @ApiOperation(value="查询发布的车辆信息")
    @GetMapping("/{id}")
    public ResponseData findByCarId(@PathVariable String id) {
        return ResponseData.success("查询成功！",carService.findByCarId(id));
    }

}
